package com.zhuoyue.biz.core.api.dto.rep;

import com.zhuoyue.biz.core.api.domain.DeviceDO;
import com.zhuoyue.biz.core.api.domain.ZigbeeDeviceProperty;
import com.zhuoyue.common.utils.Time;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.Collections;
import java.util.List;

/**
 * @author wjming
 */
@Data
public class ZigbeeDeviceRepDTO extends BaseRepDTO {

    /**
     * ZigBee设备所属网关ID
     */

    private String gatewayId;

    /**
     * 所属房间ID
     */

    private String roomId;

    /**
     * ZigBee设备模块mac地址
     */

    private String zigbeeMac;


    private String odIndex;


    private String deviceType;


    private String productType;

    /**
     * 设备名称
     */

    private String name;

    private String imgUrl;

    /**
     * 设备类型 1：ZigBee设备；2：WIFI设备
     */

    private Integer type;


    /**
     * 状态
     */
    private String switchState;


    private String lwbz;


    private String pushType;


    private String spreadingType;


    /**
     * 所属房间名称
     */

    private String roomName;

    /**
     * 状态属性(实时改变)
     */

    private String actions;

    /**
     * 属性
     */
    private String property;


    /**
     * 现在时间
     */

    private Long nowTime;

    /**
     * 设备状态时间
     */

    private Long switchTime;
    /**
     * 产品信息
     */
    private ProdInformation prodInformation;

    /***
     *设备数据转化为DTO数据
     * @param device
     * @return
     */
    public ZigbeeDeviceRepDTO deviceDoToDto(final DeviceDO device, final ZigbeeDeviceProperty property, final String actions, final List<String> functionList) {
        BeanUtils.copyProperties(device, this);
        this.setSwitchTime(Time.toLongMilli(device.getSwitchTime()));
        this.setNowTime(Time.toLongMilli(device.getNowTime()));
        this.property = property != null ? property.getProperty() : null;
        if (StringUtils.isNotEmpty(actions)) {
            this.actions = actions;
        }
        this.prodInformation = new ProdInformation().getInformation(functionList);

        return this;
    }
}

